package com.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.model.auto.SourceInfo;
import com.service.ISourceInfoService;
import com.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 资源平台
 *
 * @author zhaoyifan
 * @date 2024/12/15 17:46
 */
@RestController
@RequestMapping("/source/info")
public class SourceInfoController {

    @Autowired
    private ISourceInfoService sourceInfoService;

    /**
     * 获取资源类型列表
     *
     * @param sourceType
     * @param name
     * @return
     */
    @GetMapping("/list")
    public R data(Integer sourceType, String name) {
        if (ObjectUtils.isEmpty(sourceType)) {
            return R.error("请求资源类型参数不能为空。");
        }
        List<SourceInfo> list = sourceInfoService.list(new LambdaQueryWrapper<SourceInfo>()
                .eq(SourceInfo::getType, sourceType)
                .like(StringUtils.hasText(name), SourceInfo::getName, name)
                .orderByAsc(SourceInfo::getSortNum)
        );
        return R.ok(list);
    }
}
